#include <iostream>
#include "BinarySearchTree.h"
#include <vector>
#include <ctime>
using namespace std;
template <typename Comparable>
void BSTSorting(vector<Comparable> &_arr,int _mode =0);
int main( )
{   int test=1;
    //BinarySearchTree<int> t;
    vector<int> a ={1,2,3,4,5,6,7,8,9,10};
    BSTSorting(a);
    BSTSorting(a,test);
    vector<int> b(1000) ;
    for(int i=1;i<=1000;i++){
        b[i-1]=i;
    }
    BSTSorting(b);
    BSTSorting(b,test);
    vector<int> c(4000) ;
    for(int i=1;i<=4000;i++){
        c[i-1]=i;
    }
    BSTSorting(c);
    BSTSorting(c,test);
    vector<int> d(9000) ;
    for(int i=1;i<=9000;i++){
        d[i-1]=i;
    }
    BSTSorting(d);
    BSTSorting(d,test);
    //BSTSorting(a,test);
    return 0;
}
template <typename Comparable>
void BSTSorting(vector<Comparable> &_arr,int _mode){
    clock_t start_time=clock();
    int i=0;
    BinarySearchTree<int> t;
    if(_mode==0){
        for(i=0;i<_arr.size();i++){
            t.insert(_arr[i]);
        }
    }else if(_mode==1){
        int j=0;
        vector<Comparable> b;
        for(j=_arr.size();j>0;j--){
            srand(unsigned(time(NULL)));
            int index= rand()%j;
            b.push_back(_arr[index]);
            _arr.erase(_arr.begin()+index);
        }
        _arr=b;
        for(i=0;i<b.size();i++){
            t.insert(b[i]);
        }
    }
    if(_arr.size()<20){
        t.printTree();
    }
    clock_t end_time = clock();
    cout<<"运行函数所需的时间" <<(double)(end_time-start_time)/CLOCKS_PER_SEC<<"秒" << endl;
    //t.ntime=0;
}